package com.hhcn.friend;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * Created by Administrator on 2018/5/25.
 */
public class RecommendReduce extends Reducer<Text, IntWritable, Text, IntWritable> {

    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        int sum = 0;
        for (IntWritable dep : values) {
            sum += dep.get();
        }
        if (sum % 2 == 1) {
            sum = 1;
        } else {
            sum /= 2;
        }
        context.write(key, new IntWritable(sum));
    }
}
